var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp(), i = require("../../../mycomponent/yz_pay/yz_pay");

Page({
    behaviors: [ i ],
    data: {
        alliance_id: 0,
        goods: {},
        status: null,
        activity_status: 1,
        spec_status: null,
        end_time: "",
        active_status: "",
        timestamp: Date.parse(new Date()) / 1e3,
        countDownTime: 0,
        btnTest: "加载中...",
        Participants: [],
        joinMember: [],
        showSpecs: !1,
        groupLevel: [],
        Payshow: !1,
        btnData: [],
        payKeyboardShow: !1,
        timeData: {},
        isJoin: !1,
        shareConfig: {},
        isPlaying: !1
    },
    onLoad: function(t) {
        t.allianceid && (this.data.alliance_id = t.allianceid), this.initData(), this.getData();
    },
    onTimeChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    initData: function() {
        this.setData({
            showSpecs: !1,
            Payshow: !1,
            payKeyboardShow: !1,
            isPlaying: !1
        });
    },
    getData: function() {
        var t = this;
        a._postNetWork({
            url: a.getNetAddresss("plugin.group-work.frontend.modules.alliance.controllers.detail.index"),
            data: {
                alliance_id: this.data.alliance_id
            },
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    var n = i.data.record, o = [], s = {};
                    s.title = n.title, s.thumb = n.thumb, s.presentPrice = n.price, s.group_price = n.activity_price, 
                    s.person = n.person, s.pay = n.person - n.disparity, t.data.joinMember = n.activity_detail;
                    for (var r = 0; r < n.activity_detail.length; r += 5) o.push(n.activity_detail.slice(r, r + 5));
                    t.setData({
                        goods: s,
                        Participants: o,
                        groupModel: n.spec_id,
                        status: n.status,
                        spec_status: n.spec_status,
                        active_status: t.isWarnText(n.status, n.disparity),
                        countDownTime: 1 == n.status ? a.getTimeDifference(n.end_time) : 0,
                        isJoin: t.isJoined(),
                        btnTest: 1 == n.status ? t.isJoined() ? "邀请好友" : "我要参团" : "我要开团"
                    }), 3 == Number(n.spec_status) && t.setData({
                        btnTest: "已结束"
                    }), t.data.shareConfig.title = n.desc_title, t.data.shareConfig.imgUrl = n.thumb, 
                    t.data.shareConfig.description = n.desc_content;
                } else wx.showToast({
                    title: i.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    isJoined: function() {
        var t = wx.getStorageSync("yz_uid");
        return this.data.joinMember.findIndex(function(e) {
            return e.uid == t;
        }) > -1;
    },
    isWarnText: function(t, e) {
        var a = 0 == Number(e);
        return 1 == t ? "拼团中，离成团还差" + e + "人" : 2 == t ? "该团已拼团成功" : -1 == t ? a ? "未中奖" : "未达到拼团人数，拼团失败" : void 0;
    },
    clickBtn: function() {
        if (3 == Number(this.data.spec_status)) return wx.showToast({
            title: "已结束",
            duration: 1e3,
            icon: "none"
        }), void wx.navigateTo({
            url: "/packageI/groupWork/groupWorkIndex/groupWorkIndex"
        });
        1 == this.data.status ? this.data.isJoin || this.getGoods() : wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?name=99&activity_id=" + this.options.id
        });
    },
    countDownEnd: function() {
        this.setData({
            active_status: "等待抽奖..."
        });
    },
    gotoUrl: function(t) {
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?name=99&activity_id=" + this.options.id
        });
    },
    getGoods: function() {
        var t = this;
        a._postNetWork({
            url: a.getNetAddresss("plugin.group-work.frontend.modules.goods.controllers.detail.index"),
            data: {
                record_id: this.options.id
            },
            success: function(e) {
                var i = e.data;
                if (1 != i.result) return a.tips(i.msg);
                var n = t.data.goods;
                n.id = i.data.goods_id, n.thumb = i.data.goods_info.thumb, n.stock = i.data.stock;
                var o = i.data.specs.filter(function(e) {
                    if (e.id == t.data.groupModel) return n.price = e.min_price, n.person = e.person, 
                    e;
                });
                t.setData({
                    goods: n,
                    groupLevel: o,
                    showSpecs: !0
                });
            }
        });
    },
    getPayData: function() {
        var t = this;
        a._postNetWork({
            url: a.getNetAddresss("plugin.group-work.frontend.modules.alliance.controllers.pay.button"),
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    btnData: a.data.buttons,
                    showSpecs: !1,
                    Payshow: !0
                }) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    },
    payPost: function(i) {
        var n = this;
        return e(t.default.mark(function e() {
            var o, s, r;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (console.log(i), !n.data.isPlaying) {
                        t.next = 3;
                        break;
                    }
                    return t.abrupt("return");

                  case 3:
                    if (o = i.currentTarget.dataset.info, s = {
                        pay_type: o.value,
                        spec_id: n.data.groupModel,
                        alliance_id: n.data.alliance_id,
                        client_type: 2
                    }, !o.need_password) {
                        t.next = 10;
                        break;
                    }
                    return t.next = 8, n.getPayKeyboardPassword();

                  case 8:
                    r = t.sent, s.password = r;

                  case 10:
                    n.data.isPlaying = !0, a._getNetWork({
                        url: a.getNetAddresss("plugin.group-work.frontend.modules.alliance.controllers.apply.index"),
                        data: s,
                        success: function(t) {
                            n.data.isPlaying = !1, 1 === t.data.result ? (n.handleOtherPay(o, o.value, t.data, "groupWork"), 
                            n.setData({
                                Payshow: !1,
                                popupSpecs: !1,
                                showSpecs: !1
                            })) : (Dialog.alert({
                                title: "提示",
                                message: t.data.msg
                            }).then(function() {}), console.error(t));
                        },
                        fail: function(t) {
                            console.error(t);
                        }
                    });

                  case 12:
                  case "end":
                    return t.stop();
                }
            }, e);
        }))();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), e = "";
        return t && (e = t), {
            title: this.data.shareConfig.title,
            path: "/packageI/groupWork/groupWorkDetail/groupWorkDetail?allianceid=" + this.options.allianceid + "&id=" + this.options.id + "&mid=" + e,
            imageUrl: this.data.shareConfig.imgUrl
        };
    }
});